package com.xxx.sso.util;

import org.hashids.Hashids;

/**
 * ID等敏感字段加解密工具类
 * @author caiwl
 * @date 2020/5/7 15:29
 */
public class HashidsUtil {
    private static final String SALT = "this is my salt";
    private static final Hashids HASHIDS = new Hashids(SALT, 8);

    public static String encode(Long id) {
        return id == null ? "" : HASHIDS.encode(id);
    }

    public static Long decode(String hash) {
        return StringUtil.isEmpty(hash) ? 0L : HASHIDS.decode(hash)[0];
    }

    /**
     * 将多个参数绑定到一个参数中
     * @param numbers
     * @return
     */
    public String encode(long... numbers) {
        return HASHIDS.encode(numbers);
    }

    public static void main(String[] args) {
        System.out.println(encode(7L));
    }
}
